package com.ziyia.a287;

import static android.app.Notification.*;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.ziyia.a287.ui.login.LoginActivity;

public class MainActivity extends AppCompatActivity {

    public static final int NOTIFICATION_ID = 100;
    public static final String CHANNEL_ID = "test";
    NotificationManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        //
        String name = "测试Channel";
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("测试Channel描述信息");
        // 设计通知出现时的韶光灯
        channel.enableLights(true);
        channel.setLightColor(Color.RED);
        // 设置通知出现时振动
        channel.enableVibration(true);
        channel.setVibrationPattern(new long[]{0, 50, 100, 150});
        channel.setSound(Uri.parse("android.resource://com.ziyia.a288"), null);

        manager.createNotificationChannel(channel);

    }


    public void send(View view) {


        // 创建一个启动其他  Activity 的 Intent
        Intent intent = new Intent(MainActivity.this, LoginActivity.class);
        PendingIntent pi = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

        // 设置通知参与者
        MessagingStyle messagingStyle = new MessagingStyle("年少有为");
        messagingStyle.setConversationTitle("一条新通知");
        MessagingStyle.Message message = new MessagingStyle.Message("加薪10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
                "", System.currentTimeMillis(), "年少有为");
        messagingStyle.addMessage(message);




        Notification notification = new Builder(this, CHANNEL_ID)
                .setSmallIcon(R.drawable.user)
                .setAutoCancel(true)
                .setContentTitle("标题")
                .setContentText("内容")
                .setContentIntent(pi)
                .setStyle(messagingStyle)
                .build();

        manager.notify(NOTIFICATION_ID, notification);
    }

    public void del(View view) {
        manager.cancel(NOTIFICATION_ID);
    }
}